#include<iostream>
#include<vector>
using namespace std;



vector<vector<int>> result;
vector<int> path;
void backtracking(vector<int> nums,vector<bool> used)
{
    if(path.size()==nums.size())
    {
        result.push_back(path);
        return;
    }
    for(int i=0;i<nums.size();i++)
    {
        if(used[i])
            continue;
        path.push_back(nums[i]);
        used[i] = true;
        backtracking(nums,used);
        path.pop_back();
        used[i] = false;
    }
}
vector<vector<int>> permute(vector<int>& nums) {
    vector<bool> used(nums.size(),false);
    backtracking(nums,used);
    return result;
}
int main()
{
    cout<<"enter number:"<<endl;
    int number;
    cin>>number;
    cout<<"enter nums:"<<endl;
    vector<int> nums(number);
    for(int i=0;i<number;i++)
        cin>>nums[i];
    result = permute(nums);
    for(int i=0;i<result.size();i++)
    {
        for(int j=0;j<result[i].size();j++)
        {
            cout<<result[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}